import pygame
from pygame.sprite import Sprite


class Bullet(Sprite):
    """子弹类"""

    # 子弹的偏移量
    offset = 30

    def __init__(self, window, my_plane):
        super().__init__()
        self.image = pygame.image.load("images/bullet.png")
        self.window = window
        # 获取子弹的矩形
        self.rect = self.image.get_rect()
        # 获取我方飞机的矩形
        self.my_plane_rect = my_plane.rect
        # 设置子弹位于飞机顶部居中
        self.rect.midtop = self.my_plane_rect.midtop

    def update(self):
        """更新子弹"""
        self.rect.top -= Bullet.offset
